package com.example.ying.common.handler;

import com.example.ying.common.R;
import com.example.ying.common.filter.exception.DefinitionException;
import org.springframework.security.core.AuthenticationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理自定义异常
     *
     */
    @ExceptionHandler(value = DefinitionException.class)
    public R bizExceptionHandler(DefinitionException e) {
        return R.defineError(e);
    }

    /**
     * 处理其他异常
     *
     */
    @ExceptionHandler(value = AuthenticationException.class)
    public R authenticationException(AuthenticationException e){
        //System.out.println(e);
        return R.error(e.getMessage());
    }
//     @ExceptionHandler(value = Exception.class)
//     public R exceptionHandler( Exception e) {
//         return R.otherError(500,"服务器错误！");
//     }
//
//
//
}

